package com.zyh.system.userinfo.dao.impl;

import com.zyh.system.userinfo.dao.UserInfoDao;
import com.zyh.system.userinfo.domain.User;

import java.util.LinkedList;

/**
 * @Author zyh
 * @Date 2024/7/31 19:15
 * @Description UserInfoDao实现类
 */

public class UserInfoDaoImpl implements UserInfoDao {
    /**
     * 添加公民信息
     */
    @Override
    public boolean addUserInfo(LinkedList<User> list, User user) {
        list.push(user);
        return true;
    }

    /**
     * 查询所有信息
     * @param list
     */
    @Override
    public void showUserInfo(LinkedList<User> list) {
        //打印表头
        System.out.println("所有人信息列表如下：");
        for (User user : list) {
            System.out.println(user.getName()+"\t"+user.getId()+"\t"+user.getSex()+"\t"+user.getAddress());
        }
    }

    /**
     * 根据id修改信息功能
     * @param list
     * @return
     */
    @Override
    public boolean updateUserInfo(LinkedList<User> list,int index,User user) {
        list.set(index,user);
        return true;
    }

    /**
     * 删除信息
     * @param list
     * @param user
     * @return
     */

    @Override
    public boolean deleteUserInfo(LinkedList<User> list, User user) {
        boolean b = list.remove(user);
        return b;
    }
}
